{{ template "layout/adminheader" .}}
<main id="body">
    <div class="container">
        <div class="row">
            <div class="col-12">
                <div class="btn-group mb-3" role="group">
                    <a role="button" class="btn btn-secondary" href="/admin/setting/base.html">基本设置</a>
                    <a role="button" class="btn btn-secondary active" href="/admin/setting/smtp.html">SMTP 设置</a>
                    <a role="button" class="btn btn-secondary" href="/admin/setting/extend.html">扩展设置</a>
                    {{/*<a role="button" class="btn btn-secondary" href="?setting-sensitive_word.htm">敏感词设置</a> */}}
                </div>
                <div class="card">
                    <div class="card-body">
                        <form action="/admin/setting/smtp" method="post" id="form">
                            <div class="table-responsive arrlist">
                                <table class="table">
                                    <thead>
                                        <tr>
                                            <th>Email</th>
                                            <th>SMTP 主机</th>
                                            <th width="100" class="text-center">端口</th>
                                            <th>用户名</th>
                                            <th>密码</th>
                                            {{/*<th>删除</th>*/}}
                                        </tr>
                                    </thead>
                                    <thead>
                                    </thead>
                                    <tbody id="smtp_body">
                                        <script type="text/plain" id="smtp_tpl">
                                            <tr align="center" rowid="{rowid}">
                                    <td><input type="text" class="form-control" name="email[]" value="{email}" placeholder="Email" /></td>
                                    <td><input type="text" class="form-control" name="host[]" value="{host}"  placeholder="主机" /></td>
                                    <td width="100" class="text-center"><input type="text" class="form-control" name="port[]" value="{port}" placeholder="端口"/></td>
                                    <td><input type="text" class="form-control" name="user[]" value="{user}" placeholder="用户名"  /></td>
                                    <td><input type="password" class="form-control" name="pass[]" value="{pass}" placeholder="密码"  /></td>
                                    <td><a class="btn row_delete" role="btn">删除</a></td>
                                </tr>
                                </script>
                                        <tr align="center" rowid="0">
                                            <td>
                                                <input type="text" class="form-control" name="email" value="{{.smtpSetting.EmailUser}}" placeholder="Email">
                                            </td>
                                            <td>
                                                <input type="text" class="form-control" name="host" value="{{.smtpSetting.EmailHost}}" placeholder="主机">
                                            </td>
                                            <td width="100" class="text-center">
                                                <input type="text" class="form-control" name="port" value="{{.smtpSetting.EmailPort}}" placeholder="端口">
                                            </td>
                                            <td>
                                                <input type="text" class="form-control" name="user" value="{{.smtpSetting.EmailUser}}" placeholder="用户名">
                                            </td>
                                            <td>
                                                <input type="password" class="form-control" name="pass" value="{{.smtpSetting.EmailPass}}" placeholder="密码">
                                            </td>
                                            {{/*<td>
                                                <a class="btn row_delete" role="btn">删除</a>
                                            </td>*/}}
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                            {{/*<p><a role="button" class="btn row_add">[+]增加一行</a></p>*/}}
                            <p class="text-center">
                                <button type="button" class="btn btn-primary" id="submit" data-loading-text="正在提交..." style="width: 10rem;">确定</button>
                            </p>
                        </form>
                        <p>
                            注：<a href="https://bbs.xiuno.com/thread-19712.htm" target="_blank">如何设置 SMTP？ / How to set up SMTP ?</a>
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>

<script>
    var jform = $('#form');
    var jsubmit = $('#submit');
    jsubmit.on('click', function() {
        jform.reset();
        jsubmit.button('loading');
        var postdata = jform.serialize();
        // console.log(postdata);return;
        $.xpost(jform.attr('action'), postdata, function(code, message) {
            console.log(message);
            if(code == 200) {
                $.alert("保存成功");
                jsubmit.text(message).delay(1000).button('reset');
            } else {
                jform.find('[name="'+code+'"]').alert(message).focus();
                jsubmit.button('reset');
            }
        });
        return false;
    });

    $('#nav li.nav-item-setting').addClass('active');

</script>

{{ template "layout/adminfooter" .}}